﻿using Loki.UI.Wpf;

namespace Luna.UI.CRM.Wpf
{
    /// <summary>
    /// Logique d'interaction pour CategoryList.xaml
    /// </summary>
    public partial class CategoryListView : ViewControl<CategoryListViewModel>
    {
        public CategoryListView()
        {
            InitializeComponent();

            GRD_Categories.ConfigureGrid();

            COL_Name.Bind<DisplayableCategory>(x => x.Name);
            COL_Description.Bind<DisplayableCategory>(x => x.Description);
            COL_Color.Bind<DisplayableCategory>(x => x.Color);
            DataContextChanged += CategoryListView_DataContextChanged;
        }

        private void CategoryListView_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
        {
            ViewModel.Categories.ListChanged += Categories_ListChanged;
        }

        private void Categories_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            if (TBL_Categories != null)
            {
                TBL_Categories.BestFitColumns();
            }
        }
    }
}